﻿using BMSQ.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BMSQ.Admin.User
{
    public partial class Modify : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    string User_ID = Request.Params["id"];
                    ShowInfo(User_ID);
                }
            }
        }

        private void ShowInfo(string User_ID)
        {
            BLL.UserList bll = new BLL.UserList();
            Model.UserList model = bll.GetModel(User_ID);
            this.lblUser_ID.Text = model.User_ID;
            this.txtUser_Name.Text = model.User_Name;
            this.txtUser_Phone.Text = model.User_Phone;
            this.txtUser_Email.Text = model.User_Email;
            this.txtUser_Pwd.Text = model.User_Pwd;
            this.txtCheck_Code.Text = model.Check_Code;
            this.txtUser_TrueName.Text = model.User_TrueName;
            this.txtUser_Sex.Text = model.User_Sex.ToString();
            this.txtUser_Address.Text = model.User_Address;
            this.txtUser_Image.Text = model.User_Image;
            this.txtUser_Money.Text = model.User_Money.ToString();
            this.txtCreated_Date.Text = model.Created_Date.ToString();
            this.txtLogin_Date.Text = model.Login_Date.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtUser_Name.Text.Trim().Length == 0)
            {
                strErr += "User_Name不能为空！\\n";
            }
            if (this.txtUser_Phone.Text.Trim().Length == 0)
            {
                strErr += "User_Phone不能为空！\\n";
            }
            if (this.txtUser_Email.Text.Trim().Length == 0)
            {
                strErr += "User_Email不能为空！\\n";
            }
            if (this.txtUser_Pwd.Text.Trim().Length == 0)
            {
                strErr += "User_Pwd不能为空！\\n";
            }
            if (this.txtCheck_Code.Text.Trim().Length == 0)
            {
                strErr += "Check_Code不能为空！\\n";
            }
            if (this.txtUser_TrueName.Text.Trim().Length == 0)
            {
                strErr += "User_TrueName不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtUser_Sex.Text))
            {
                strErr += "User_Sex格式错误！\\n";
            }
            if (this.txtUser_Address.Text.Trim().Length == 0)
            {
                strErr += "User_Address不能为空！\\n";
            }
            if (this.txtUser_Image.Text.Trim().Length == 0)
            {
                strErr += "User_Image不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtUser_Money.Text))
            {
                strErr += "User_Money格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtCreated_Date.Text))
            {
                strErr += "Created_Date格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtLogin_Date.Text))
            {
                strErr += "Login_Date格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string User_ID = this.lblUser_ID.Text;
            string User_Name = this.txtUser_Name.Text;
            string User_Phone = this.txtUser_Phone.Text;
            string User_Email = this.txtUser_Email.Text;
            string User_Pwd = this.txtUser_Pwd.Text;
            string Check_Code = this.txtCheck_Code.Text;
            string User_TrueName = this.txtUser_TrueName.Text;
            int User_Sex = int.Parse(this.txtUser_Sex.Text);
            string User_Address = this.txtUser_Address.Text;
            string User_Image = this.txtUser_Image.Text;
            int User_Money = int.Parse(this.txtUser_Money.Text);
            DateTime Created_Date = DateTime.Parse(this.txtCreated_Date.Text);
            DateTime Login_Date = DateTime.Parse(this.txtLogin_Date.Text);


            Model.UserList model = new BLL.UserList().GetModel(User_ID);
            model.User_ID = User_ID;
            model.User_Name = User_Name;
            model.User_Phone = User_Phone;
            model.User_Email = User_Email;
            model.User_Pwd = User_Pwd;
            model.Check_Code = Check_Code;
            model.User_TrueName = User_TrueName;
            model.User_Sex = User_Sex;
            model.User_Address = User_Address;
            model.User_Image = User_Image;
            model.User_Money = User_Money;
            model.Created_Date = Created_Date;
            model.Login_Date = Login_Date;

            BLL.UserList bll = new BLL.UserList();
            bll.Update(model);
            MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}